package main

import (
	"flag"
)

type Config struct {
	PrintVersionAndExit bool
	Debug               bool
	Key                 string
	Host                string
	Port                int
	User                string
}

func NewConfig() *Config {
	var c *Config = &Config{
		PrintVersionAndExit: false,
		Debug:               false,
		Key:                 "jetbrains.key",
		Host:                "127.0.0.1",
		Port:                3927,
		User:                "Jetbrains User",
	}
	c.ParseCmdlineOpt()
	return c
}

func (c *Config) ParseCmdlineOpt() {
	flag.BoolVar(&c.PrintVersionAndExit, "v", c.PrintVersionAndExit, "Print Version")
	flag.BoolVar(&c.Debug, "debug", c.Debug, "Enable Debug Mode")
	flag.StringVar(&c.Key, "key", c.Key, "Private Key Used for Signature, Support Local File and HTTP(S) Schema Both")
	flag.StringVar(&c.Host, "host", c.Host, "HTTP Server Host")
	flag.IntVar(&c.Port, "port", c.Port, "HTTP Server Port")
	flag.StringVar(&c.User, "user", c.User, "User Who Use Jetbrains Products")

	// will invoke os.Exit(2) while parse error
	flag.Parse()
}
